package chapter06;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test13_collections {
    public static void main(String[] args) {
        ArrayList<Integer> n = new ArrayList<>();
        Collections.addAll(n,1,2,3,4,5,6);
        System.out.println(n);
        Collections.reverse(n);
        System.out.println(n);
        Collections.sort(n);
        System.out.println(n);
        Collections.shuffle(n);
        System.out.println(n);
        Collections.swap(n,0,n.size()-1);
        System.out.println(n);
        //排序规则自定义
        ArrayList<String> n2 = new ArrayList<>();
        Collections.addAll(n2,"1","11","2","22");
        Collections.sort(n2);
        System.out.println(n2);
        //按照数字进行排序
        Collections.sort(n2, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                Integer a1 = Integer.valueOf(o1);
                Integer a2 = Integer.valueOf(o2);
                return a1-a2;
            }
        });
        System.out.println(n2);
    }
}
